package com.mlf.prototype.spring;

import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.stereotype.Component;

@Component
public class SingletonWithLookup {

    //使用@Lookup注解，Spring会重写此方法
    @Lookup
    public PrototypeBean getPrototypeBean() {
        return null; // 具体实现由Spring提供
    }

    public void doSomething() {
        PrototypeBean bean1 = getPrototypeBean();
        PrototypeBean bean2 = getPrototypeBean();
        System.out.println("---Using @Lookup: --- ");
        System.out.println("bean1 :" + bean1.getInstanceId());
        System.out.println("bean2 :" + bean2.getInstanceId());
        System.out.println("bean1 == bean2 :" + (bean1 == bean2));
    }
}
